home *** CD-ROM | disk | FTP | other *** search
/ Ghost Rider iactivecard / Ghost Rider iactivecard.iso / pc / concetration.swf / scripts / DefineSprite_14 / frame_2 / DoAction.as
Encoding:
Text File  |  2007-04-06  |  3.9 KB  |  147 lines

  1. function createCard(n, w, h)
  2. {
  3.    empty.push(n);
  4.    this.createEmptyMovieClip("card" + n,n);
  5.    with(this["card" + n])
  6.    {
  7.       lineStyle(0,0,100);
  8.       beginFill(153,60);
  9.       moveTo(w / 2,0);
  10.       lineTo(w / 2,h / 2);
  11.       lineTo((- w) / 2,h / 2);
  12.       lineTo((- w) / 2,(- h) / 2);
  13.       lineTo(w / 2,(- h) / 2);
  14.       lineTo(w / 2,0);
  15.       endFill();
  16.       createEmptyMovieClip("back",1);
  17.       back.loadMovie("cards/card_back.jpg");
  18.       back._x = 2 - w / 2;
  19.       back._y = 2 - h / 2;
  20.       createEmptyMovieClip("front",2);
  21.       front.createEmptyMovieClip("container",3);
  22.       front.createEmptyMovieClip("backgr",2);
  23.       with(front.backgr)
  24.       {
  25.          moveTo((- w) / 2,(- h) / 2);
  26.          lineStyle(0,0,0);
  27.          beginFill(3355443,100);
  28.          lineTo(w / 2,(- h) / 2);
  29.          lineTo(w / 2,h / 2);
  30.          lineTo((- w) / 2,h / 2);
  31.          lineTo((- w) / 2,(- h) / 2);
  32.          endFill();
  33.       }
  34.       front.onEnterFrame = function()
  35.       {
  36.          tot = this.container.getBytesTotal();
  37.          car = this.container.getBytesLoaded();
  38.          if(tot == car && tot > 200)
  39.          {
  40.             this._parent._parent.centerImage(this._parent);
  41.             delete this.onEnterFrame;
  42.          }
  43.       };
  44.    }
  45. }
  46. function placeImages()
  47. {
  48.    act_img = 1;
  49.    img = 0;
  50.    while(img < imgs_n)
  51.    {
  52.       k = 0;
  53.       while(k < 2)
  54.       {
  55.          act = Math.round(Math.random() * (empty.length - 1));
  56.          this["card" + empty[act]].img_id = act_img;
  57.          this["card" + empty[act]].front.container.loadMovie("cards/card_img" + act_img + ".jpg");
  58.          this["card" + empty[act]].onRelease = function()
  59.          {
  60.             this.rotateCard(0,0);
  61.             this.enabled = false;
  62.             MovieClip.prototype.enabled = false;
  63.          };
  64.          empty.splice(act,1);
  65.          k++;
  66.       }
  67.       act_img++;
  68.       img++;
  69.    }
  70. }
  71. function generateGameField(cards, distance, hdistance)
  72. {
  73.    Ypos = card_h / 2 + hdistance;
  74.    Xpos = card_w / 2 + distance;
  75.    c = 0;
  76.    while(c < cards)
  77.    {
  78.       createCard(c,card_w,card_h);
  79.       if(c % row_card == 0 && c > 0)
  80.       {
  81.          Ypos += this["card" + c]._height + hdistance;
  82.          Xpos = card_w / 2 + distance;
  83.       }
  84.       this["card" + c]._x = Xpos;
  85.       this["card" + c]._y = Ypos;
  86.       Xpos += this["card" + c]._width + distance;
  87.       c++;
  88.    }
  89.    placeImages();
  90.    score = 0;
  91.    turns = 0;
  92.    score_txt = "0";
  93. }
  94. function checkCards()
  95. {
  96.    if(this[selcards[0]].img_id == this[selcards[1]].img_id)
  97.    {
  98.       score++;
  99.       eval(selcards[0])._visible = eval(selcards[1])._visible = false;
  100.    }
  101.    else
  102.    {
  103.       eval(selcards[0]).rotateCard(1,1);
  104.       eval(selcards[1]).rotateCard(1,1);
  105.       eval(selcards[0]).enabled = eval(selcards[1]).enabled = true;
  106.    }
  107.    if(score == 25)
  108.    {
  109.       play();
  110.    }
  111.    turns++;
  112.    score_txt = turns;
  113.    selcards = [];
  114.    MovieClip.prototype.enabled = true;
  115. }
  116. centerImage = function(target)
  117. {
  118.    target.front._visible = false;
  119.    target.front.container._x -= target.front.container._width / 2;
  120.    target.front.container._y -= target.front.container._height / 2;
  121. };
  122. empty = new Array();
  123. selcards = [];
  124. MovieClip.prototype.rotateCard = function(v, i)
  125. {
  126.    this.operazione = v != 0 ? -0.35 : 0.35;
  127.    this.incremento = i != 0 ? 10 : 100;
  128.    selcards.push(this._name);
  129.    this.onEnterFrame = function()
  130.    {
  131.       this.incremento += this.operazione;
  132.       this._xscale = 100 * Math.sin(this.incremento);
  133.       if(this._xscale > 0)
  134.       {
  135.          this.front._visible = v != 1 ? true : false;
  136.       }
  137.       if(this._xscale >= 99)
  138.       {
  139.          delete this.onEnterFrame;
  140.          selcards.length >= 2 ? null : (MovieClip.prototype.enabled = true);
  141.          !(v == 0 && selcards.length > 1) ? null : checkCards();
  142.       }
  143.    };
  144. };
  145. generateGameField(n_card,card_wdistance,card_hdistance);
  146. stop();
  147.